import { get, post, put, del } from '@/utils/request';
import type { ApiResponse } from '@/types/api';
import type { SysRole } from '@/types/system';

export function roleList(params?: { roleName?: string; roleCode?: string }) {
  return get<ApiResponse<SysRole[]>>('/role/list', { params });
}

export function roleGet(roleId: number) {
  return get<ApiResponse<SysRole>>(`/role/${roleId}`);
}

export function roleAdd(body: SysRole) {
  return post<ApiResponse<string>>('/role/add', body);
}

export function roleUpdate(body: SysRole) {
  return put<ApiResponse<string>>('/role/update', body);
}

export function roleDelete(roleId: number) {
  return del<ApiResponse<string>>(`/role/delete/${roleId}`);
}

export function roleAssignMenus(roleId: number, menuIdList: number[]) {
  return post<ApiResponse<string>>(`/role/${roleId}/menus`, menuIdList);
}